package com.ruoyi.iot.controller;

import com.ruoyi.iot.service.InfluxService;
import com.ruoyi.iot.vo.InfluxQueryResultVO;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/iot/opcua")
public class SimpleOpcUaController {

    @Autowired
    private OpcUaAsyncCollector collector;
    @Autowired
    private InfluxService influxService;

    /**
     * 点位导入或配置修改后，调用本接口重新启动采集任务
     */
    @Anonymous
    @PostMapping("/reload")
    public AjaxResult reloadCollector() {
        collector.reloadAllPoints();
        return AjaxResult.success("采集器已加载!");
    }

    /**
     * 停止采集
     */
    @Anonymous
    @PostMapping("/stop")
    public AjaxResult stopCollector() {
        collector.stopAllPoints();
        return AjaxResult.success("采集器已停止!");
    }

    @Anonymous
    @GetMapping("/influx/query")
    public AjaxResult queryInfluxData(String point, String ip, String area) {
        List<InfluxQueryResultVO> data = influxService.querySensorData();
        return AjaxResult.success(data);
    }


}